package com.youlin.controller;

import com.youlin.dto.*;
import com.youlin.dto.req.SignInReqDto;
import com.youlin.dto.res.DeadManResDto;
import com.youlin.service.BygDeadManService;
import com.youlin.service.BygSignInService;
import com.youlin.untils.MyBeanUtil;
import com.youlin.mybean.UnIntercept;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;

@ApiSort(10)
@Api(tags = {"10 - 来宾签到模块"})
@RestController
@RequestMapping("/bygSignIn")
public class BygSignInController {

    @Autowired
    private BygSignInService bygSignInService;
    @Autowired
    private BygDeadManService bygDeadManService;

    /**
     * 来宾签到获取逝者信息
     *
     * @return
     */
    @UnIntercept
    @PostMapping("/guest/findDeadManByAmUuId")
    @ApiOperationSort(1)
    @ApiOperation(value = "1 - 来宾签到获取逝者信息", notes = "请求参数：data = 预约UUID")
    public BaseDataResDto<DeadManResDto> findDmByAmUuIdAtSignIn(@RequestBody BaseReqDto<String> baseReqDto,
                        @RequestHeader(name = "version", required = false, defaultValue = "0") String version) {
        String amUuId = baseReqDto.getData();
        if (StringUtils.isBlank(amUuId)) return new BaseDataResDto<>(Status.PARAMETERERROR);
        return bygDeadManService.findDmByAmUuIdAtSignIn(amUuId, version);
    }

    /**
     * 来宾签到
     *
     * @return
     */
    @PostMapping("/guest/saveSignIn")
    @ApiOperationSort(2)
    @ApiOperation(value = "2 - 来宾签到", notes = "响应参数：status-message = " +
            "{1026-签到已结束，感谢您的参与；1038-内容含有敏感词}")
    public BaseResDto<Status, String> saveSignIn(@RequestBody BaseReqDto<SignInReqDto> baseReqDto) {
        SignInReqDto data = baseReqDto.getData();
        if (MyBeanUtil.isParamError(data)) return new BaseResDto<>(Status.PARAMETERERROR);
        return bygSignInService.saveSignIn(data);
    }

}

